<?php
	/*
	 * # ------------------------------------------------------------------------
# JA Halite - Version 1.0 - Licence Owner JA180572
# ------------------------------------------------------------------------
# Copyright (C) 2004-2009 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
# @license - Copyrighted Commercial Software
# Author: J.O.O.M Solutions Co., Ltd
# Websites:  http://www.joomlart.com -  http://www.joomlancers.com
# This file may not be redistributed in whole or significant part.
# ------------------------------------------------------------------------
	 */
  // no direct access
defined('_JEXEC') or die('Restricted access');

class JElementJacolorpicker extends JElement {
	/*
	 * Category name
	 *
	 * @access	protected
	 * @var		string
	 */
	var	$_name = 'Jacolorpicker';
	
	function fetchElement($name, $value, &$node, $control_name){
		
		$uri = $this->getCurrentURL();
		$this->loadjscss( $uri ); 	

		$string =  '<span id="preview-'.$name.'" style=" float:left; padding-left:3px;"><img id="img-'.$name.'" src="'.$uri.'/jacolorpicker/images/rainbow.png" alt="[r]" width="16" style="margin-right:4px;cursor:hand;cursor:pointer" height="16"/></span>';
		$string .= ' <input type="text" class="text_area" value="'.$value.'" '
				.'id="params'.$name.'" name="params['.$name.']"/>';	
		$string .= "
				<script type='text/javascript'>
				window.addEvent('domready', function() {
					var r = new MooRainbow('img-".$name."', {
						'startColor': [58, 142, 246],
						id:'img-".$name."',
						imgPath:'".$uri."/jacolorpicker/images/',
						'onChange': function(color) {
							$('params".$name."').value = color.hex.replace('#','');
					
							$('preview-".$name."').setStyle('background', '#' + $('params".$name."').value );
						}
					});
					
					if( $('params".$name."').value != '' ) {
						$('preview-".$name."').setStyle('background', '#' + $('params".$name."').value );
					}
				});
			</script>	
		";
		return $string;	
	}
	
	/**
	 * get current url
	 */
	function getCurrentURL(){
		$uri = str_replace(DS,"/",str_replace( JPATH_SITE, JURI::base (), dirname(__FILE__) ));
		$uri = str_replace("/administrator", "", $uri);
		return $uri;
	}
	
	/**
	 * load css and js file
	 */
	function loadjscss( $uri ){
		if (!defined ('_JA_PARAM_HELPER_RAINBOW_')) {
			define ('_JA_PARAM_HELPER_RAINBOW_', 1);

			JHTML::stylesheet('jacolorpicker/mooRainbow.css', $uri."/");
			JHTML::script('jacolorpicker/mooRainbow.js', $uri."/");
		}
	
	} 
}
?>